package month4.day25;

import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.util.Scanner;

public class Text {
    public static void main(String[] args) {
        File file = new File("market.txt");
        Scanner in = new Scanner(System.in);
        Market market = new Market();
        ObjectInputStream ois = null;
        try {
            ois = new ObjectInputStream(new FileInputStream(file));
            market = (Market) ois.readObject();
            ois.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        while (true) {
            System.out.println("1:积分累计" + "2:积分兑换" + "3:查询剩余积分" + "4:修改密码" + "5:开卡" + "6:退出");
            int n = in.nextInt();
            if (n == 1) {
                System.out.println("输入用户名");
                String name = in.next();
                System.out.println("输入用户密码");
                String code = in.next();
                System.out.println("请输入花费金额");
                double money=in.nextDouble();
                market.leiji(name,code,money);
            } else if (n == 2) {
                System.out.println("输入用户名");
                String name = in.next();
                System.out.println("输入用户密码");
                String code = in.next();
                System.out.println("100分兑换餐巾纸；\n" +
                        "400分兑换剃须刀；\n" +
                        "50000分兑换汽车；");
                System.out.println("请输入兑换的商品");
                String shangpin = in.next();
                market.duihuan(name,code,shangpin);
            } else if (n == 3) {
                System.out.println("输入用户名");
                String name = in.next();
                System.out.println("输入用户密码");
                String code = in.next();
                market.shengyui(name, code);
            } else if (n == 4) {
                System.out.println("输入用户名");
                String name = in.next();
                System.out.println("输入用户密码");
                String code = in.next();
                System.out.println("输入用户新密码");
                String newcode = in.next();
                market.xiugai(name, code, newcode);
            } else if (n == 5) {
                System.out.println("输入用户名");
                String name = in.next();
                System.out.println("输入用户密码");
                String code = in.next();
                //market.kaika(name,code);
                System.out.println("开卡" + (market.kaika(name, code) ? "成功" : "失败"));
            } else if (n == 6) {
                return;
            } else {
                System.out.println("输入用户名");
                String name = in.next();
                System.out.println("输入用户密码");
                String code = in.next();
                market.shanchu(name, code);
            }
        }
    }
}
